package com.yanqu.road.server.gameplayer.module.union;

import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.enums.union.trade.eUnionTradeLogType;
import com.yanqu.road.entity.enums.union.trade.eUnionTradeRouteState;
import com.yanqu.road.entity.log.cross.LogUnionTradeSendPatronsLog;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.entity.union.UnionUpgradeInfo;
import com.yanqu.road.entity.union.trade.*;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.UnionConfigMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.server.manger.union.UnionMgr;
import com.yanqu.road.server.manger.union.UnionNoticeMgr;
import com.yanqu.road.server.manger.union.UnionTradeMgr;
import com.yanqu.road.server.pb.UnionTradePb;
import com.yanqu.road.server.pb.WorldMessagePb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.*;

/**
 * 商会贸易（商贸）
 */
public class UnionTradeModule extends GeneralModule {

    public UnionTradeModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public void afterLogin() {

        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
           return;
        }
        UnionTradeMgr.resetData(unionUid);       //检测跨天的商贸（待前端对接次数开启后可删除）
        syncCanJoinRedHot();
    }

    public void syncCanJoinRedHot() {
        String unionUid = player.getUserInfo().getUnionUid();
        if (StringUtils.isNullOrEmpty(unionUid)) {
            return;
        }
        boolean canJoin = UnionTradeMgr.hasRouteCanJoin(unionUid, player);
        WorldMessageProto.RedHotNotifyMsg.Builder redHotMsg = WorldMessagePb.parseRedHotNotifyMsg(eRedHotNotifyType.UnionTradeCanJoin.getValue(), canJoin == true ? 1 : 0, null);
        player.sendPacket(Protocol.U_RED_HOT_NOTIFY, redHotMsg);
    }

    public void resetOneDay(){
        PatronsModule patronsModule = player.getModule(PatronsModule.class);
        List<UserPatrons>  userPatronsList = patronsModule.getUserPatronsList();
        UserPatrons userPatrons;
        for(UserPatrons tempPatrons : userPatronsList){
            userPatrons = patronsModule.getUserPatrons(tempPatrons.getPatronsId());
            if (!DateHelper.isToday(new Date(userPatrons.getResetTime()))) {
                userPatrons.setResetTime(System.currentTimeMillis());
                userPatrons.setUnionTradeSend(false);
            }
        }
    }

    //未读的特殊事件
    public void syncUnReadEventList(int routeId){
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            return;
        }
        UnionTradeTeamData unionTradeTeamData =  UnionTradeMgr.getTeamDataByUnionUinAndRouteId(unionUid, routeId);
        if(unionTradeTeamData != null){
            List<UnionTradeLog> unionTradeLogDataList = unionTradeTeamData.getNewLogDataList();
            List<UnionTradeLog> allEventLogList = new ArrayList<>();
            for(UnionTradeLog logData : unionTradeLogDataList){
                if(UnionTradeMgr.isEventLogData(logData.getEventId())){
                    allEventLogList.add(logData);
                }
            }
            if(allEventLogList.size() == 0){
                return;
            }
            List<UnionTradeLog> needSendList = new ArrayList<>();
            List<UnionTradeEventRead>  eventReadList = unionTradeTeamData.getUserReadList();
            Iterator<UnionTradeEventRead> eventReadIterator = eventReadList.iterator();

            UnionTradeEventRead userEventRead = null;
            while(eventReadIterator.hasNext()){
                UnionTradeEventRead eventRead = eventReadIterator.next();
                if (eventRead.getUserId() == player.getUserId()) {
                    userEventRead = eventRead;
                }
            }
            if (userEventRead == null) {
                userEventRead = new UnionTradeEventRead(player.getUserId(), -1);
                synchronized (eventReadList) {
                    eventReadList.add(userEventRead);
                }
            }

            if (userEventRead.getIdx() == allEventLogList.size() - 1) {
                return;
            }

            for (int i = userEventRead.getIdx() + 1; i < allEventLogList.size(); i++) {
                needSendList.add(allEventLogList.get(i));
            }
            userEventRead.setIdx(allEventLogList.size() - 1);
            unionTradeTeamData.setUpdateOption();
            if(needSendList.size() > 0) {
                UnionTradeProto.UnReadEventListRespMsg.Builder respMsg = UnionTradeProto.UnReadEventListRespMsg.newBuilder();
                respMsg.setRet(0);
                respMsg.addAllLogDataList(UnionTradePb.parseTradeLogDataTempMsgList(needSendList));
                player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_UNREAD_EVENT_LIST, respMsg);
            }
        }
    }

    //开启商贸路线
    public int openTradeRoute(int routeId, int goodId){
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            return GameErrorCode.E_UNION_TRADE_NO_UNION;
        }

        UnionTradeRouteInfo routeInfo = UnionConfigMgr.getUnionTradeRouteInfo(routeId);
        UnionInfo unionInfo = UnionMgr.getUnionInfo(unionUid);
        if(null == unionInfo){
            return GameErrorCode.E_UNION_TRADE_ROUTE_NOT_FOUND;
        }
        if(!UnionTradeMgr.isRouteUnlock(routeInfo, unionInfo)){
            return GameErrorCode.E_UNION_TRADE_ROUTE_LOCKED;         //未解锁
        }

        //开启条件
        UnionMember unionMember = UnionMgr.getUnionMember(unionUid, player.getUserId());

        Map<Integer, UnionTradeTeamData> unionTradeTeamDataMap = UnionTradeMgr.getTeamDataMapByUnionUid(unionUid);
        UnionTradeTeamData unionTradeTeamData = unionTradeTeamDataMap.get(routeId);

        Object lockObj;
        if(unionTradeTeamData == null){
            lockObj =  unionTradeTeamDataMap;
        }else{
            lockObj =  unionTradeTeamData;
        }
        synchronized (lockObj) {
            boolean isNew = false;
            unionTradeTeamData = unionTradeTeamDataMap.get(routeId);
            if(unionTradeTeamData == null){
                unionTradeTeamData = new UnionTradeTeamData();
                unionTradeTeamData.setRouteId(routeId);
                unionTradeTeamData.setUnionUid(unionUid);
                unionTradeTeamData.setRestTime(DateHelper.getCurrentTime());
                unionTradeTeamData.setInsertOption();
                isNew = true;
            }else {
                int curState = UnionTradeMgr.calTradeRouteStateVal(routeInfo, unionTradeTeamData);   //待客户端按次数判定是否开启时，只需判断结束发奖状态
                if (eUnionTradeRouteState.UnOpen.getIntValue() != curState || (eUnionTradeRouteState.Close.getIntValue() == curState && !unionTradeTeamData.isSendReward())) {
                    return GameErrorCode.E_UNION_TRADE_ROUTE_BEEN_OPENED;
                }
            }

            //是否有开启次数
            if(unionTradeTeamData.getOpenNum() >= UnionTradeMgr.ROUTE_OPEN_NUM_ONE_DAY){
                return GameErrorCode.E_UNION_TRADE_ROUTE_OPEN_NUM_NOT_ENOUGH;
            }

            Property property = new Property();
            Property consume = PropertyHelper.parseStringToProperty(routeInfo.getConsume(), "\\|");
            if(consume.getCountByGoodsId(goodId).compareTo(BigInteger.ZERO) == 0){
                return GameErrorCode.E_REQUEST_ARGUMENT_ERROR;                        //参数类型不对
            }
            //是否足够消耗
            if (GameConfig.GAME_ITEM_UNION_WEALTH == goodId) {
                if (unionMember.getPosition() > eUnionPosition.DeputyMaster.getValue()) {
                    return GameErrorCode.E_UNION_TRADE_ONLY_MASTER_CAN_USE_WEALTH;    //只有商会正、副会长可用商会财富
                }
                property.setGood(GameConfig.GAME_ITEM_UNION_WEALTH,  consume.getCountByGoodsId(GameConfig.GAME_ITEM_UNION_WEALTH));
                if (!player.getModule(CurrencyModule.class).removeCurrency(property, eLogMoneyType.Union, eLogMoneyType.UnionTradeRouteOpen)) {
                    return GameErrorCode.E_UNION_TRADE_WEALTH_NO_ENOUGH;              //商会财富不足
                }
            }else {
                property.setGood(goodId, consume.getCountByGoodsId(goodId));
                if (!player.getModule(CurrencyModule.class).removeCurrency(property, eLogMoneyType.Union, eLogMoneyType.UnionTradeRouteOpen)) {
                    return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;                       //道具不足
                }
            }

            //重置商队
            unionTradeTeamData.reset();
            unionTradeTeamData.setStateVal(eUnionTradeRouteState.UnStart.getIntValue());
            unionTradeTeamData.setOpenTime(DateHelper.getCurrentTime());
            unionTradeTeamData.setOpenUser(player.getUserId());
            //次数+1
            unionTradeTeamData.setOpenNum(unionTradeTeamData.getOpenNum() + 1);
            //随机事件初始化  3
            initTradeEventData(routeInfo, unionTradeTeamData);

            //记录商贸日志
            UnionTradeMgr.addLogData(unionTradeTeamData, eUnionTradeLogType.OpenRoute, player.getUserInfo());
            if(isNew) {
                UnionTradeMgr.getTeamDataMapByUnionUid(unionUid).put(routeId, unionTradeTeamData);
            }
            //商会频道消息
            String content = WorldMessageMgr.encodeContent(player.getUserInfo().getNickName(), PropertyHelper.parsePropertyToString(property), routeId);
            WorldMessageProto.WorldMessageTempMsg.Builder chatMsg = WorldMessagePb.parseWorldMessageTempMsg(player.getUserInfo(),
                    eMessageType.UnionTradeMsg.getValue(), eChatContentType.Common.getContentType(), content, unionTradeTeamData.getOpenTime(), 0, null);
            WorldMessageMgr.addWorldMessage(player, chatMsg);
            //记录到商会日志
            UnionNoticeMgr.addNotice(player, unionUid, eUnionNoticeType.Trade.getValue(), player.getUserInfo().getNickName(), PropertyHelper.parsePropertyToString(property), routeId);

            //DataAnalyticsMgr.trackOreWarOpenRoad(player,routeId);
        }
        UnionTradeMgr.syncRouteCanJoinToMember(unionUid);  //红点
        return 0;
    }

    //随机选取路线事件
    private List<Integer> randomCollectionOfEvent(RandomHelper randomHelper, List<Integer> all, int num){
        List<Integer> result = new ArrayList<>();
        if(num == all.size()){//全量
            result.addAll(all);
        }else {
            for(int i = 0; i < num; i++) {
                int randIndex = randomHelper.next(0, all.size());
                result.add(all.get(randIndex));
            }
        }
        return result;
    }

    //随机选取路线事件时间（不重复）
    private List<Integer> randomCollectionOfEvent2(RandomHelper randomHelper, List<Integer> all, int num){
        List<Integer> result = new ArrayList<>();
        if(num == all.size()){//全量
            result.addAll(all);
        }else {
            List<Integer> fetchList = new ArrayList<>(all);
            for(int i = 0; i < num; i++) {
                int randIndex = randomHelper.next(0, fetchList.size());
                result.add(fetchList.get(randIndex));
                fetchList.remove(randIndex);
            }
        }
        return result;
    }

    //初始路线的随机事件（按时间有序）
    private void initTradeEventData(UnionTradeRouteInfo routeInfo, UnionTradeTeamData unionTradeTeamData) {
        RandomHelper randomHelper = new RandomHelper();
        int eventNum = randomHelper.next(routeInfo.getEventNum().get(0), 1 + routeInfo.getEventNum().get(1));  //确定路线事件个数
        if(routeInfo.getEventNum().get(1) <= routeInfo.getEventTime().size()) {   //最大值比集合小
            List<Integer> list = randomCollectionOfEvent2(randomHelper, routeInfo.getEventTime(), eventNum);
            Collections.sort(list);
            unionTradeTeamData.setEventTimeList(list);
            unionTradeTeamData.setEventList(randomCollectionOfEvent(randomHelper, routeInfo.getEventList(), eventNum));
            unionTradeTeamData.setTakeEventIndex(-1);
        }
    }

    //加入商贸队伍
    public int joinTradeTeam(int routeId, List<Integer> patronsIdList){
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            return GameErrorCode.E_UNION_NO_JOIN_UNION;
        }

        List<Integer> hadSend = getSendPatronsIdList();
        for(Integer patronsId : patronsIdList){
            if(hadSend.contains(patronsId)) {
                return GameErrorCode.E_UNION_TRADE_PATRONS_BEEN_SEND;        //门客已被派遣过
            }
        }
        hadSend = UnionTradeMgr.findPatronsByRouteIdAndUserId(unionUid, routeId, player.getUserId());
        for(Integer patronsId : patronsIdList){
            if(hadSend.contains(patronsId)) {
                return GameErrorCode.E_UNION_TRADE_ROUTE_HAD_JOIN;          //门客已被派遣过,(避免隔天路线，门客派遣重置造成路线重复派遣)
            }
        }

        UnionTradeTeamData unionTradeTeamData = UnionTradeMgr.getTeamDataByUnionUinAndRouteId(unionUid, routeId);
        UnionTradeRouteInfo unionTradeRouteInfo = UnionConfigMgr.getUnionTradeRouteInfo(routeId);

        int stateVal = UnionTradeMgr.calTradeRouteStateVal(unionTradeRouteInfo, unionTradeTeamData);
        if(eUnionTradeRouteState.Trade.getIntValue() != stateVal && eUnionTradeRouteState.UnStart.getIntValue() != stateVal){
            return GameErrorCode.E_UNION_TRADE_ONLY_TRADE_CAN_JOIN;      //只有进行中的商贸与未出发的商贸才可加入
        }

        synchronized (unionTradeTeamData){
            stateVal = UnionTradeMgr.calTradeRouteStateVal(unionTradeRouteInfo, unionTradeTeamData);
            if(eUnionTradeRouteState.Trade.getIntValue() != stateVal && eUnionTradeRouteState.UnStart.getIntValue() != stateVal){
                return GameErrorCode.E_UNION_TRADE_ONLY_TRADE_CAN_JOIN;      //只有进行中的商贸与未出发的商贸才可加入
            }

            //人数上限
            Set<Long> userIdList = UnionTradeMgr.getUserIdSet(unionTradeTeamData.getUserJoinDataList());
            UnionInfo unionInfo = UnionMgr.getUnionInfo(unionUid);
            UnionUpgradeInfo unionUpgradeInfo = UnionConfigMgr.getUnionUpgradeInfo(unionInfo.getExperience());
            if(userIdList.size() >= unionUpgradeInfo.getMaxMemberCount() && !userIdList.contains(getUserId())){
                return GameErrorCode.E_UNION_TRADE_ROUTE_TEAM_USER_NUM_EXCEED;
            }

            long allEarns = 0L;
            for(UnionTradeTeamUserJoin joinData : unionTradeTeamData.getUserJoinDataList()){
                allEarns += joinData.getPatronsEarn();
            }
            if(unionTradeRouteInfo.getCondition() <= allEarns){
                return GameErrorCode.E_UNION_TRADE_ROUTE_PATRONS_EARN_EXCEED;      //赚钱超出队伍要求
            }
            long currentTime = DateHelper.getCurrentTime();
            List<UnionTradeTeamUserJoin> newJoinDataList = new ArrayList<>();
            for(Integer patronsId : patronsIdList) {
                UnionTradeTeamUserJoin userJoinData =  new UnionTradeTeamUserJoin();
                UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(patronsId);
                BigInteger patronsEarn = userPatrons.getAbility();
                userJoinData.setPatronsEarn(patronsEarn.longValue());
                userJoinData.setPatronsId(patronsId);
                userJoinData.setUserId(player.getUserId());
                userJoinData.setJoinTime(currentTime);
                userJoinData.setSkinId(userPatrons.getSkinId());
                userJoinData.setUserAliasId(player.getUserInfo().getUserAliasId());
                userJoinData.setDecoration(UserMgr.getDecoration(player.getUserId()));
                newJoinDataList.add(userJoinData);
            }
            int oldSize = unionTradeTeamData.getUserJoinDataList().size();
            //是否第一个加入
            if (oldSize == 0) {
                unionTradeTeamData.setStateVal(eUnionTradeRouteState.Trade.getIntValue());
                unionTradeTeamData.setStartTradeTime(currentTime/1000);
            }
            unionTradeTeamData.addAllJoinData(newJoinDataList);

            //标记门客已派遣
            Map<Integer, UserPatrons> userPatronsMap = player.getModule(PatronsModule.class).getUserPatronsMap();
            for(Integer patronsId : patronsIdList){
                userPatronsMap.get(patronsId).setUnionTradeSend(true);
            }
            //记录商贸日志
            UnionTradeMgr.addLogData(unionTradeTeamData, eUnionTradeLogType.UserJoin, player.getUserInfo(), null, currentTime, newJoinDataList);

            //记录玩家详情
            unionTradeTeamData.addUserInfo(UserMgr.getUserBaseInfo(player.getUserId(), GameServer.getInstance().getServerId()));

            //运营日志
            for(UnionTradeTeamUserJoin join : newJoinDataList) {
                //路线等级
                AutoLogMgr.add(new LogUnionTradeSendPatronsLog(unionUid, getUserId(), unionTradeRouteInfo.getId(), join.getPatronsId(), join.getPatronsEarn(), ++oldSize));
            }
            //DataAnalyticsMgr.trackOreWarJoinRoad(player,routeId);
        }
        UnionTradeMgr.syncRouteCanJoinToMember(unionUid);
        return 0;
    }

    //获取用户派遣门客
    public List<Integer> getSendPatronsIdList() {
        List<Integer> hadSend = new ArrayList<>();
        List<UserPatrons>  userPatronsList = player.getModule(PatronsModule.class).getUserPatronsList();
        for(UserPatrons userPatrons : userPatronsList){
            if(userPatrons.isUnionTradeSend()) {
                hadSend.add(userPatrons.getPatronsId());
            }
        }
        return hadSend;
    }

    //获取路线最新状态（routeId, 0表示全部路线；teamDetail  是否包含队伍详情）
    public UnionTradeProto.RouteListRespMsg.Builder getNewestUnionRouteData(int  routeId, boolean teamDetail){
        UserInfo userInfo = UserMgr.getUserInfo(player.getUserId());
        if(StringUtils.isNullOrEmpty(userInfo.getUnionUid())) {
            return null;
        }
        //log.info(" getNewestUnionRouteData start ");
        long startTimeMillis = System.currentTimeMillis();
        String unionUid = userInfo.getUnionUid();
        UnionInfo unionInfo = UnionMgr.getUnionInfo(unionUid);
        UnionTradeProto.RouteListRespMsg.Builder respMsg = UnionTradeProto.RouteListRespMsg.newBuilder();
        //路线
        Map<Integer, UnionTradeRouteInfo> routeInfoMap =  UnionConfigMgr.getUnionTradeRouteInfoMap();
        //队伍
        Map<Integer, UnionTradeTeamData> teamDataMap = UnionTradeMgr.getTeamDataMapByUnionUid(unionUid);
        for(UnionTradeRouteInfo routeInfo : routeInfoMap.values()){
            if(routeId != 0){//不为0代表只查询指定线路
                if(routeId != routeInfo.getId()){
                    continue;
                }
            }
            UnionTradeProto.RouteTempMsg.Builder routeMsg = UnionTradeProto.RouteTempMsg.newBuilder();
            routeMsg.setRouteId(routeInfo.getId());
            //是否解锁
            if(UnionTradeMgr.isRouteUnlock(routeInfo, unionInfo)){
                routeMsg.setStateVal(eUnionTradeRouteState.UnOpen.getIntValue());
            }else{
                routeMsg.setStateVal(eUnionTradeRouteState.Locked.getIntValue());
            }
            //解锁状态下，查询队伍信息
            if(routeMsg.getStateVal() != eUnionTradeRouteState.Locked.getIntValue()){
                UnionTradeTeamData teamData = teamDataMap.get(routeInfo.getId());
                if(teamData != null){
                    UnionTradeProto.TeamDataTempMsg.Builder  teamMsg  = UnionTradeProto.TeamDataTempMsg.newBuilder();
                    int calState;
                    synchronized (teamData){
                        calState = UnionTradeMgr.calTradeRouteStateVal(routeInfo, teamData);
                    }
                    routeMsg.setStateVal(calState);
                    teamMsg.setStateVal(calState);
                    //队伍详情
                    List<UnionTradeTeamUserJoin> unionTradeTeamUserJoinDataList = teamData.getNewUserJoinDataList();
                    teamMsg.setOpenTime(teamData.getOpenTime());
                    teamMsg.setStartTradeTime(Long.valueOf(teamData.getStartTradeTime()).intValue());
                    long earn = 0L;
                    for(UnionTradeTeamUserJoin joinData : unionTradeTeamUserJoinDataList){
                        earn = earn + joinData.getPatronsEarn();
                    }
                    teamMsg.setPatronsEarns(earn);
                    if(!StringUtils.isNullOrEmpty(teamData.getExpectReward())) {
                        teamMsg.setExpectReward(teamData.getExpectReward());
                    }
                    if(teamDetail){
                        for(UnionTradeTeamUserJoin userJoinData : unionTradeTeamUserJoinDataList){
                            //if(userJoinData.isQuit()){   //退出门客也要显示在列表
                            //    continue;
                            //}
                            UnionTradeProto.TeamUserPatronsTempMsg.Builder userPatronsMsg =   UnionTradeProto.TeamUserPatronsTempMsg.newBuilder();
                            userPatronsMsg.setUserId(userJoinData.getUserId());
                            userPatronsMsg.setUserAliasId(userJoinData.getUserAliasId());
                            userPatronsMsg.setDecoration(userJoinData.getDecoration());
                            userPatronsMsg.setSkinId(userJoinData.getSkinId());
                            userPatronsMsg.setJoinTime(userJoinData.getJoinTime());
                            userPatronsMsg.setPatronsId(userJoinData.getPatronsId());
                            userPatronsMsg.setPatronsEarns(userJoinData.getPatronsEarn());
                            teamMsg.addUserPatronsJoinList(userPatronsMsg);
                        }
                    }
                    if(teamData.getStateVal() == eUnionTradeRouteState.Close.getIntValue() && teamData.isSendReward()){
                        teamMsg.setCanOpen(UnionTradeMgr.ROUTE_OPEN_NUM_ONE_DAY > teamData.getOpenNum());   //结束商队是否可开启
                    }
                    List<UserBaseInfo> userBaseInfoList = teamData.getNewUserInfoList();
                    for(UserBaseInfo userBaseInfo : userBaseInfoList){
                        teamMsg.addUserInfoList(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
                    }
                    routeMsg.setTeamData(teamMsg);
                }
            }else{
                routeMsg.setStateVal(eUnionTradeRouteState.Locked.getIntValue());
            }
            respMsg.addRouteTempList(routeMsg);
        }
        log.info(" getNewestUnionRouteData cost {} ", System.currentTimeMillis() - startTimeMillis);
        return respMsg;
    }
}
